package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Supplier;
import com.qidianit.mes.pojo.pro.Process;
import com.qidianit.mes.pro.service.ProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.relation.RelationSupport;
import java.util.concurrent.locks.ReadWriteLock;

/**
 * @Description:
 * @Author: YanJiRan
 * @Date: 2025/9/17 - 下午2:16
 */
@RestController
@RequestMapping("/process")
public class ProcessController {
    @Autowired
    private ProcessService processService;

    @GetMapping("/autoCode")
    public Result<String> autoCode(){
        return processService.autoCode();
    }

    @GetMapping("/page")
    public Result<PageInfo<Process>> list(Process process, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size){
        return processService.selectList(process,page,size);
    }

    @PostMapping("/add")
    public Result<Process> save(@RequestBody Process process){
        return processService.saveProcess(process);
    }

    @GetMapping("code/{code}")
    public Result<Process> getByCode(@PathVariable("code") String processCode){
        return processService.selectByCode(processCode);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Process process){
        return processService.updateById(process);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        return processService.deleteById(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long[] id){
        return processService.batchDelete(id);
    }
}
